<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Soft navigation visited link paint tests.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/soft-navigation-helper.js"></script>
</head>
<body>
  <main id=main>
  <a id=link>Click me!</a>
  <a id=visited>link that is really long so it is the LCP</a>
  </main>
  <script>
    const visited = document.getElementById("visited");
    const fake_url = "./fake_" + Math.random();
    visited.href = fake_url;
    const visitFakeURLAndAddInvisibleText = () => {
      requestAnimationFrame(() => requestAnimationFrame(() => {
        history.replaceState({}, "", fake_url);
      }));
      const main = document.getElementById("main");
      const div = document.createElement("div");
      const text = document.createTextNode("Lorem Ipsum");
      div.appendChild(text);
      main.appendChild(div);
    }
    const link = document.getElementById("link");
    testSoftNavigation({
      addContent: async () => {
        await visitFakeURLAndAddInvisibleText();
      },
      link: link,
      validate: async () => {
        await new Promise(r => step_timeout(r, 100));
        const postVisitedLcp = await getLcpEntries();
        assert_not_equals(postVisitedLcp[postVisitedLcp.length - 1].id,
                          "visited",
                          "Soft Nav LCP ID should not be visited");
      },
      test: "Test that a visited link doesn't trigger LCP after a soft " +
            "navigation is detected"});
  </script>
</body>
</html>
